home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex30.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  823 b   |  31 lines

  1. Program ex30;
  2.  
  3. { Program to demonstrate the TCollection.Free method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M : PMyObject;
  9.     I,InitMem : Longint;
  10.  
  11. begin
  12.   Randomize;
  13.   C:=New(PCollection,Init(120,10));
  14.   InitMem:=Memavail;
  15.   Writeln ('Initial memory : ',InitMem);
  16.   For I:=1 to 100 do
  17.     begin
  18.     M:=New(PMyObject,Init);
  19.     M^.SetField(I-1);
  20.     C^.Insert(M);
  21.     end;
  22.   Writeln ('Added 100 Items. Memory available : ',Memavail);
  23.   Write ('Lost : ',Initmem-Memavail,' bytes.');
  24.   Write   ('(Should be 100*',SizeOF(TMyObject));
  25.   Writeln ('=',100*SizeOf(TMyObject),')');
  26.   With C^ do
  27.     While Count>0 do Free(At(Count-1)); 
  28.   Writeln ('Freed all objects. Memory available : ',Memavail);
  29.   Writeln ('Lost : ',Initmem-Memavail,' bytes.');
  30.   Dispose(C,Done);
  31. end.